import React, { useState } from 'react';
import { ScoreModal } from '../../../../components';
import { TaskOperateType } from '../../../../utils';
import { fetchOperateDetails } from '../../../containers/MyTaskInfoModal/util';
import { modalTypes } from '../../../../components/ScoreModal/modalTypes';

const ScoreDetail = ({ ScoreDetailRef }) => {
    const [modalData, setModalData] = useState();
    const [modalVisible, setModalVisible] = useState(false);
    const [modalType, setModalType] = useState('');
    const [modalTableData, setModalTableData] = useState([]);

    const showScoreModal = async (id, recId, OperateType) => {
        const resultData = await fetchOperateDetails(id, recId);
        setModalData(resultData);
        if (OperateType === TaskOperateType.SCORE) {
            // 评分
            setModalTableData(resultData.taskScoreRuleDetails);
            setModalType(modalTypes.SCORE_DETAIL.key);
        }
        if (OperateType === TaskOperateType.AUTO_SCORE) {
            // 自动评分
            setModalTableData(resultData.taskScoreRuleDetails);
            setModalType(modalTypes.AUTO_SCORE_DETAIL.key);
        }
        if (OperateType === TaskOperateType.RECHECK_APPLY) {
            // 重评申请
            setModalTableData(resultData);
            setModalType(modalTypes.RE_RATE_APPLY_DETAIL.key);
        }
        if (OperateType === TaskOperateType.RECHECK) {
            // 重评
            setModalTableData(resultData.taskScoreRuleDetails);
            setModalType(modalTypes.RE_SCORE_DETAIL.key);
        }
        if (OperateType === TaskOperateType.ABANDON_SCORE) {
            // 放弃评分
            setModalType(modalTypes.GIVE_UP_RATE_DETAIL.key);
        }
        if (OperateType === TaskOperateType.LAUNCH_SCORE) {
            // 发起评分
            setModalType(modalTypes.LAUNCH_RATE_DETAIL.key);
        }
        setModalVisible(true);
    };

    React.useImperativeHandle(ScoreDetailRef, () => ({
        showScoreModal
    }));

    return (
        <>
            <ScoreModal
                data={modalData}
                modalTableData={modalTableData}
                visible={modalVisible}
                type={modalType}
                setVisible={setModalVisible}
                isDetail
            ></ScoreModal>
        </>
    );
};

export default ScoreDetail;
